package com.example.taximeter.mapper;

import com.example.taximeter.bean.Price;
import com.example.taximeter.bean.Role;
import com.example.taximeter.bean.RolePrivilege;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 角色
 */
@Mapper
public interface RoleMapper {

    //查询角色(id)
    @Select("select id , role_name from tab_roles where where id = #{id,jdbcType=INTEGER}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "rolename", column = "role_name")
    })
    Role findRoleById(@Param("id")Integer id);

    //查询角色(名称)
    @Select("select role_id , role_name from tab_roles where role_name = #{rolename,jdbcType=VARCHAR} ")
    @Results({
            @Result(property = "roleid", column = "role_id"),
            @Result(property = "rolename", column = "role_name")
    })
    List<Role> findRoleByRolename(@Param("rolename") String rolename);

    //查询角色列表
    @Select("select role_id , role_name from tab_roles")
    @Results({
            @Result(property = "roleid", column = "role_id"),
            @Result(property = "rolename", column = "role_name")
    })
    List<Role> findRoleList();

    //添加角色
    @Insert("insert into tab_roles (role_name)\n" +
            "    values (#{role.rolename,jdbcType=VARCHAR})")
    @Options(useGeneratedKeys=true, keyProperty="role.roleid")
    boolean addRole(@Param("role") Role role);

    //添加角色--权限
    @Insert("insert into tab_role_privilege (role_id,privilege_id)\n" +
            "    values (#{roleid,jdbcType=INTEGER},#{privilegeid,jdbcType=INTEGER})")
    boolean addRolePrivilege(@Param("roleid") Integer roleid,@Param("privilegeid") Integer privilegeid);


    @SelectProvider(type = ActivityMapperProvider.class, method = "findRoleAll")
    @Results({
            @Result(property = "roleid", column = "role_id"),
            @Result(property = "rolename", column = "role_name")
    })
    List<Role> findRoleAll(Role role);

    //修改角色名
    @Update("update tab_roles set role_name = #{rolename,jdbcType=VARCHAR} where role_id = #{roleid,jdbcType=INTEGER}")
    boolean updateRole(Role role);

    //删除用户信息
    @Delete("delete from tab_roles where role_id = #{roleid,jdbcType=INTEGER}")
    boolean deleteRole(Integer roleid);
}
